package GameObjs;

import java.awt.Graphics;

import manager.LayerManager;
import render.Model;
import render.SimpleModel;

/**
 * @说明
 * @author YOU友
 * @所有元素的基类
 * @二作 Passerby
 * @修改 
 * 在render函数中加入参数g
 * 在默认构造函数中将model实例化
 */
public abstract class GameObject {

	private int x;
	private int y;
	private int z;
	private int w;
	private int h;
	private Model model;
	private boolean active = true;
	
	public GameObject () {
//		由于draw函数必须要有model，故在此
		model = new SimpleModel();
	}
	
	public GameObject(int x,int y, int z, int w,int h,Model model,boolean active) {
		this.x=x;
		this.y=y;
//		因为z轴只有0，1，2，故做一个条件判断和修正
		if (z >= 3 || z < 0) {
			z = 0;
		}
		this.z = z;
		LayerManager lm = LayerManager.get();
		lm.setLayer(this, 0, z);
		this.w=w;
		this.h=h;
		if (model == null) {
//			如果为空则置为空的简单model，使render函数不至于不执行
			model = new SimpleModel();
		}
		this.model=model;
		this.active=active;
	}
	
	public GameObject create (String data)
	{
		return this;
	}
	
	public void render (Graphics g)
	{
		model.draw(g, x, y, z);
	}
	
	public abstract void ObjRun ();
	
	public int getX() {
		return x;
	}
	public void setX(int x) {
		this.x = x;
	}
	public int getY() {
		return y;
	}
	public void setY(int y) {
		this.y = y;
	}
	
	public int getZ() {
		return z;
	}
	public void setZ(int z) {
		if (z > 2 || z < 0) {
			z = 0;
		}

		LayerManager lm = LayerManager.get();
		lm.setLayer(this, this.z, z);
		this.z = z;
	}
	
	public Model getModel() {
		return model;
	}
	public void setModel(Model model) {
		this.model = model;
	}
	public boolean isActive() {
		return active;
	}
	public void setActive(boolean active) {
		this.active = active;
	}
	public int getW() {
		return w;
	}
	public void setW(int w) {
		this.w = w;
	}
	public int getH() {
		return h;
	}
	public void setH(int h) {
		this.h = h;
	}

	public void keypress(int key, boolean b) {

	}

	public void mouse(boolean bl) {
		// TODO 鑷姩鐢熸垚鐨勬柟娉曞瓨鏍�
		
	}
	
	
	
}
